<html>
<head><meta charset="utf-8"><title>Cross crate-hygiene roots · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Cross.20crate-hygiene.20roots.html">Cross crate-hygiene roots</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240119024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Cross%20crate-hygiene%20roots/near/240119024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Cross.20crate-hygiene.20roots.html#240119024">(May 24 2021 at 22:08)</a>:</h4>
<p>I've been attempting to changing decoding of hygiene to preserve the 'root' from other crates, instead of mapping foreign roots to the 'root' of the current crate. However, as described here <a href="https://github.com/rust-lang/rust/issues/84429#issuecomment-830851900">https://github.com/rust-lang/rust/issues/84429#issuecomment-830851900</a>, there's a lot of code that seems to be relying on the existence of a single root (instead of a 'forest' of <code>ExpnId</code> trees).</p>
<p>I've been trying the alternate approach I described, where we 'attach' the roots of other crates to the root of the current crate. However, this approach has some problems of its own - since we copy foreign <code>SyntaxContext</code>s into the current crate when decoding, we could end up with a complicated situtation when multiple crates are involved. For example, we could decode the root <code>SyntaxContext</code> from another crate, creating the tree <code>crate_a_root#0 -&gt; crate_b_root#1</code>. We would then serialize that tree into the current crate's metadata, and then decode it from a <em>different</em> crate, creating the tree <code>crate_c_root#0 -&gt; crate_a_root#1 -&gt; crate_b_root#1</code>, instead of <code>crate_c_root#0 -&gt; crate_b_root#1</code>.</p>
<p>I'm not sure if this alternate approach will end up being any less difficult to implement, or whether or not it will even be correct. cc <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span></p>



<a name="240709909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Cross%20crate-hygiene%20roots/near/240709909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Cross.20crate-hygiene.20roots.html#240709909">(May 29 2021 at 16:31)</a>:</h4>
<blockquote>
<p>I've been trying the alternate approach I described, where we 'attach' the roots of other crates to the root of the current crate.</p>
</blockquote>
<p>I'd expect this approach to create more problems than solve, modifying algorithms to not expect a single root should be better.<br>
(This is mostly an intuition, I don't currently have time to look into anything in detail.)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>